<template>
  <button @click="download">下载</button>
</template>
<script>
import { download } from '@/api/article';
export default {
  data() {
    return {};
  },
  methods: {
    downlaod(param) {
      download(param)
        .then(data => {
          if (!data) {
            this.$Message.error('下载内容为空');
            return;
          }
          const url = window.URL.createObjectURL(new Blob([data]));
          const link = document.createElement('a');
          const etcdCluster = 'download';
          link.style.display = 'none';
          link.href = url;
          link.setAttribute('download', etcdCluster + '.zip');

          document.body.appendChild(link);
          link.click();
          // 释放URL对象所占资源
          window.URL.revokeObjectURL(url);
          // 用完即删
          document.body.removeChild(link);
        })
        .catch(err => {
          console.log('err: ', err);
        });
    }
  }
};
</script>
<style scoped></style>
